#ifndef HEAD_H
#define HEAD_H
#include<iostream>
using namespace std;

struct listseq{
    int number[100];
    int length;
};


class  sequence{
private:
    listseq ls;
public:
    sequence();
    void showlist();
    void findnum();
    void length_input();
    int deletemin();
    void deleteelement();
    void inputrange();
    void deleterange();
    int r[2];
    void deletenumer(int flag);
};


sequence::sequence(){
    int i=0;
    length_input();

    while(i<ls.length){
        cin>>ls.number[i];
        i++;
    }
}

void sequence::showlist(){
    int i=0;
    while(i<ls.length){
        cout<<ls.number[i]<<"\t";
        i++;
    }
}

void sequence::length_input(){
    int l;
    cout<<"please input the length of arraylist:";
    cin>>l;
        if(l){
            ls.length=l;
        }
        else{
            length_input();
        }
}

int sequence::deletemin(){
    int flag=0;
    int i=1;

    int min=ls.number[0];
    while(i<ls.length){
        if(ls.number[i]<min){
            min=ls.number[i];
            flag=i;
        }
        i++;
    }
    int p=min;

    if(flag!=ls.length){
        ls.number[flag]=ls.number[ls.length-1];
        ls.number[ls.length-1]=ls.number[ls.length+1];
        ls.length--;
    }
    int q=ls.number[flag];
    cout<<endl<<q<<endl;
    return p;
}


//02_02

void sequence::deleteelement(){
    int target;
    int flag=ls.length;
    cout<<"imput the number to delete: ";
    cin>>target;
    int i=0;
    while(i<ls.length){
        if(ls.number[i]==target)
            flag=i;
        i++;
    }
    i=flag;
    while(i<ls.length){
        ls.number[i]=ls.number[i+1];
        i++;
    }
    ls.length--;
}


//02_03

void sequence::deleterange(){
    int i=0;
    inputrange();
    while(i<ls.length){
        if(ls.number[i]>=r[0]&&ls.number[i]<=r[1]){
            deletenumer(i);
        }
        else
            i++;
    }
}

void sequence::deletenumer(int flag){
    int i=flag;
    while(i<ls.length){
        ls.number[i]=ls.number[i+1];
        i++;
    }
    ls.length--;
}


void sequence::inputrange(){
    int s,t;
    cout<<"delete the nodes which holds the number within range [s,t]"<<endl
       <<"input s:";
    cin>>s;
    cout<<"\ninput t:";
    cin>>t;
    if(s<=t){
        r[0]=s;
        r[1]=t;
    }
    else{
        cout<<"\nplease input the range again.\n";
        inputrange();
    }
}
#endif // HEAD_H
